#!/bin/bash

# 定义回收站目录
TRASH_DIR="$HOME/.trash"

# 1. 检查并创建回收站目录
if [ ! -d "$TRASH_DIR" ]; then
    mkdir -p "$TRASH_DIR"
fi

# 2. 检查是否传入待操作文件
if [ $# -eq 0 ]; then
    echo "Usage: $0 file1 [file2 file3 ...]"
    exit 1
fi

# 3. 用户确认删除
echo "Are you sure to delete these files? (Y/n)"
read -r reply
# 处理默认回车（视为确认）
if [ -z "$reply" ]; then
    reply="Y"
fi
# 转为小写判断
#reply=$(echo "$reply" | tr '[:upper:]' '[:lower:]')
if [ "$reply" = "n" -o "$reply" = "N" ]; then
    echo "No file removed"
    exit 0
fi

# 4. 循环处理每个文件（双引号包裹变量，支持空格）
for file in "$@"; do
    # 检查文件/目录是否存在
    if [ ! -e "$file" ]; then
        echo "$file: No such file or directory"
        continue
    fi
    # 移动到回收站（-b 避免覆盖同名文件）
    mv -b "$file" "$TRASH_DIR/"
    echo "Moved '$file' to $TRASH_DIR/"
done
